package avd6;

import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

public class ZhiShu {

	public static void main(String[] args) {

		List<Integer> list = new ArrayList<>();
		try {
			FileOutputStream out = new FileOutputStream("F:\\质数表.txt");
			for (int i = 1; i <= 10000; i++) {
				int j;
				for (j = 2; j * j < i; j++) {
					if (i != 1 && i != 2 && i % j == 0) {
						break;
					}

				}
				if ((i == 1 || i == 2) || i % j != 0) {
					// System.out.println(i);
					list.add(i);
				}

			}
			// System.out.println(list);

			String b = list.toString();
			byte[] c = b.getBytes();

			for (int i = 0; i < list.size(); i++) {

				out.write((list.get(i) + ",").getBytes());
				if (i % 10 == 9) {
					out.write("\r\n".getBytes());
				}
			}

			// out.write("\t".getBytes());

			out.close();

		} catch (Exception e) {

			e.printStackTrace();

		}
	}
}